package com.hfjyz.judge.judge.bean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.hfjyz.base.bean.BaseBean;
import com.hfjyz.base.constant.BaseConstant;
import com.hfjyz.base.entity.JudgeEntity;
import com.hfjyz.base.util.BaseUtil;
import com.hfjyz.base.util.CodeUtil;
import com.hfjyz.base.util.IdcardUtil;

public class JudgeBean extends BaseBean {
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 6694013097664237545L;
    protected Integer id = null;
    protected String idNo = null;
    protected String name = null;
    protected int sex = -1;
    protected String birthday = null;
    protected String hometown = null;
    protected String graduatedFrom = null;
    protected int topEducation = -1;
    protected int educationType = -1;
    protected String subject = null;
    protected String workUnit = null;
    protected String title = null;
    protected String post = null;
    protected String skillsCert = null;
    protected String workPhone = null;
    protected String cellPhone = null;
    protected String homePhone = null;
    protected String imAddress = null;
    protected String mailAddress = null;
    protected String workAddress = null;
    protected String address = null;
    protected String trainExperience = null;
    protected String workExperience = null;
    protected String speciality = null;
    protected Integer categoryId = null;
    protected String categoryName = null;
    protected byte[] photo = null;
    protected Integer isSigned = null;
    protected String remark = null;
    protected Integer callTimes = null;

    public JudgeBean() {
    }

    public JudgeBean(JudgeEntity entity) {
        setId(entity.getId());
        setIdNo(entity.getIdNo());
        setName(entity.getName());
        setSex(entity.getIsMale() ? 1 : 0);
        SimpleDateFormat sdf = new SimpleDateFormat(BaseConstant.DATE_PATTERN_BAR);
        if (entity.getBirthday() != null) {
            String date = sdf.format(entity.getBirthday());
            setBirthday(date);
        }
        setGraduatedFrom(entity.getGraduatedFrom());
        setTopEducation(entity.getTopEducation());
        setEducationType(entity.getEducationType());
        setSubject(entity.getSubject());
        setWorkUnit(entity.getWorkUnit());
        setTitle(entity.getTitle());
        setPost(entity.getPost());
        setSkillsCert(entity.getSkillsCert());
        setWorkPhone(entity.getWorkPhone());
        setCellPhone(entity.getCellPhone());
        setImAddress(entity.getImAddress());
        setMailAddress(entity.getMailAddress());
        setWorkAddress(entity.getWorkAddress());
        setAddress(entity.getAddress());
        setTrainExperience(entity.getTrainExperience());
        setWorkExperience(entity.getWorkExperience());
        setPhoto(entity.getPhoto());
        setHomePhone(entity.getHomePhone());
        setHometown(entity.getHometown());
        setSpeciality(entity.getSpeciality());
        setCategoryId(entity.getCategoryId().getId());
        setCategoryName(entity.getCategoryId().getCategoryName());
        setIsSigned(entity.getIsSigned());
        setRemark(entity.getRemark());
        if (entity.getRegDate() != null) {
            String date = sdf.format(entity.getRegDate());
            setRegDate(date);
        }
        setCallTimes(entity.getCallTimes());
    }

    public String getHometown() {
        return hometown;
    }

    public void setHometown(String hometown) {
        this.hometown = hometown;
    }

    public String getHomePhone() {
        return homePhone;
    }

    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }

    public byte[] getPhoto() {
        return photo;
    }

    public void setPhoto(byte[] photo) {
        this.photo = photo;
    }

    @Override
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getGraduatedFrom() {
        return graduatedFrom;
    }

    public void setGraduatedFrom(String graduatedFrom) {
        this.graduatedFrom = graduatedFrom;
    }

    public int getTopEducation() {
        return topEducation;
    }

    public void setTopEducation(int topEducation) {
        this.topEducation = topEducation;
    }

    public int getEducationType() {
        return educationType;
    }

    public void setEducationType(int educationType) {
        this.educationType = educationType;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getWorkUnit() {
        return workUnit;
    }

    public void setWorkUnit(String workUnit) {
        this.workUnit = workUnit;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public String getSkillsCert() {
        return skillsCert;
    }

    public void setSkillsCert(String skillsCert) {
        this.skillsCert = skillsCert;
    }

    public String getWorkPhone() {
        return workPhone;
    }

    public void setWorkPhone(String workPhone) {
        this.workPhone = workPhone;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

    public String getImAddress() {
        return imAddress;
    }

    public void setImAddress(String imAddress) {
        this.imAddress = imAddress;
    }

    public String getMailAddress() {
        return mailAddress;
    }

    public void setMailAddress(String mailAddress) {
        this.mailAddress = mailAddress;
    }

    public String getWorkAddress() {
        return workAddress;
    }

    public void setWorkAddress(String workAddress) {
        this.workAddress = workAddress;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTrainExperience() {
        return trainExperience;
    }

    public void setTrainExperience(String trainExperience) {
        this.trainExperience = trainExperience;
    }

    public String getWorkExperience() {
        return workExperience;
    }

    public void setWorkExperience(String workExperience) {
        this.workExperience = workExperience;
    }

    public String getSpeciality() {
        return speciality;
    }

    public void setSpeciality(String speciality) {
        this.speciality = speciality;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public Integer getIsSigned() {
        return isSigned;
    }

    public void setIsSigned(Integer isSigned) {
        this.isSigned = isSigned;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getCallTimes() {
        return callTimes;
    }

    public void setCallTimes(Integer callTimes) {
        this.callTimes = callTimes;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categorName) {
        this.categoryName = categorName;
    }

    @Override
    public List<String> toJsonArray(int index) {
        List<String> result = new ArrayList<String>();
        result.add(String.valueOf(index + 1));
        result.add(categoryName);
        result.add(name);
        result.add(CodeUtil.getSexString(sex));
        result.add(hometown);
        result.add(birthday);
        result.add(CodeUtil.getEducation(topEducation));
        result.add(workUnit);
        result.add(post);
        result.add(cellPhone);
        result.add(mailAddress);
        result.add(String.valueOf(callTimes));

        return result;
    }

    @Override
    public String validate() {
        List<String> errorList = new ArrayList<String>();
        // 身份证
        if (!IdcardUtil.validateCard(idNo)) {
            errorList.add("身份证号码不正确");
        }

        if (name == null || name.isEmpty()) {
            errorList.add("姓名必须输入");
        } else if (name.length() > 16) {
            errorList.add("姓名长度不能超过16");
        }

        if (sex != 0 && sex != 1) {
            errorList.add("性别只能输入‘男’或‘女’");
        }

        if (!BaseUtil.isEmpty(birthday)) {
            if (BaseUtil.parseDate(birthday) == null) {
                errorList.add("生日日期格式或内容输入不正确");
            }
        }

        if (!BaseUtil.isEmpty(hometown) && hometown.length() > 32) {
            errorList.add("籍贯长度不能超过32");
        }

        if (!BaseUtil.isEmpty(graduatedFrom) && graduatedFrom.length() > 32) {
            errorList.add("毕业院校长度不能超过32");
        }

        if (!BaseUtil.isEmpty(subject) && subject.length() > 32) {
            errorList.add("所学专业长度不能超过32");
        }

        if (!BaseUtil.isEmpty(workUnit) && workUnit.length() > 64) {
            errorList.add("姓名长度不能超过64");
        }

        if (!BaseUtil.isEmpty(title) && title.length() > 32) {
            errorList.add("职称长度不能超过32");
        }

        if (!BaseUtil.isEmpty(post) && post.length() > 32) {
            errorList.add("职务长度不能超过32");
        }

        if (!BaseUtil.isEmpty(skillsCert) && skillsCert.length() > 32) {
            errorList.add("技能资格证书长度不能超过32");
        }

        if (!BaseUtil.isEmpty(workPhone) && !BaseUtil.checkPhone(workPhone)) {
            errorList.add("办公电话填写不正确");
        }

        if (!BaseUtil.isEmpty(cellPhone) && !BaseUtil.checkCellPhone(cellPhone)) {
            errorList.add("手机号码填写不正确");
        }

        if (!BaseUtil.isEmpty(homePhone) && !BaseUtil.checkPhone(homePhone)) {
            errorList.add("家庭电话填写不正确");
        }

        if (!BaseUtil.isEmpty(imAddress) && !BaseUtil.checkQQ(imAddress)) {
            errorList.add("QQ填写不正确");
        }

        if (!BaseUtil.isEmpty(mailAddress) && !BaseUtil.checkMail(mailAddress)) {
            errorList.add("邮箱填写不正确");
        }

        if (!BaseUtil.isEmpty(workAddress) && workAddress.length() > 128) {
            errorList.add("单位地址长度不能超过128");
        }

        if (!BaseUtil.isEmpty(address) && address.length() > 128) {
            errorList.add("地址长度不能超过128");
        }

        if (!BaseUtil.isEmpty(trainExperience) && trainExperience.length() > 2048) {
            errorList.add("教育和培训经历长度不能超过2048");
        }

        if (!BaseUtil.isEmpty(workExperience) && workExperience.length() > 2048) {
            errorList.add("工作经历长度不能超过2048");
        }

        if (!BaseUtil.isEmpty(speciality) && speciality.length() > 2048) {
            errorList.add("个人优势与特长长度不能超过2048");
        }

        if (!BaseUtil.isEmpty(regDate)) {
            if (BaseUtil.parseDate(regDate) == null) {
                errorList.add("登记时间格式或内容输入不正确");
            }
        }
        if (!BaseUtil.isEmpty(remark) && remark.length() > 2048) {
            errorList.add("备注长度不能超过2048");
        }
        return getErrMsgForUI(errorList);
    }

    public void decodeChangeLine() {
        setTrainExperience(BaseUtil.decodeChangeLine(getTrainExperience()));
        setWorkExperience(BaseUtil.decodeChangeLine(getWorkExperience()));
        setSpeciality(BaseUtil.decodeChangeLine(getSpeciality()));
        setRemark(BaseUtil.decodeChangeLine(getRemark()));
    }
}
